<?php
namespace app\admin\model;

use think\Model;

class SupplierContact extends BaseModel
{
    protected $attributes = [
        'gender' => [
            1 => '男',
            0 => '女'
        ]
    ];

    public function getSupplierName(){
        return $this->hasOne(Supplier::class,'id','supid')->bind(['supname']);
    }

    public function getCountryName(){
        return $this->hasOne(RegionCountry::class, 'id','country')->bind(['country_name' => 'name']);
    }

    public function getGenderValueAttr($value, $data)
    {
        if ($data['gender']) {
            return isset($this->attributes['gender'][$data['gender']]) ? $this->attributes['gender'][$data['gender']] : '';
        }
        return '';
    }

    public function getFieldEnum($field)
    {
        if ('ALL' === strtoupper($field)) {
            return [
                'gender' => $this->attributes['gender']
            ];
        } else {
            return [$field => $this->$field];
        }
    }

    public function getGenderAttr($value, $data)
    {
        return intval($value);
    }

    public function getCountryAttr($value, $data)
    {
        return intval($value);
    }
}

?>
